#include <bits/stdc++.h>
// 2024/11/08
// tag: dynamic programming, bitwise operation
using namespace std;

int C, N, dp[1000001], m, o[100001], v;
string s;
// Main function, the entry point of the program
signed main()
{
    // Turn off synchronization of input and output streams to improve input and output efficiency
    ios::sync_with_stdio(false);
    // Unbind the input stream and output stream to avoid flushing the output buffer immediately after performing an input operation
    cin.tie(0);
    cout.tie(0);

    // Read in the number of colors C and the number of items N
    cin >> C >> N;
    // Calculate 2 to the power of C to represent all possible color combinations
    int t = 1 << C;
    // Initialize the dynamic programming array dp, and initialize all elements to the maximum value INT_MAX
    for (int i = 0; i < t; i++)
        dp[i] = 1e9;

    // Read in the color information of each item
    for (int i = 1; i <= N; i++)
    {
        // Read in a string representing the color state of the item
        cin >> s;
        // Traverse each character in the string to calculate the color encoding of the item
        for (int j = 0; j < C; j++)
            if (s[j] == 'G')
                // If the character is '1', set the corresponding color bit to 1
                o[i] += (1 << j);
        // Set the dp value corresponding to the item's color encoding to 0, indicating that this color combination can be covered by this item
        dp[o[i]] = 0;
    }

    // Use dynamic programming algorithm to calculate the minimum number of covering items for each color combination
    for (int i = 1; i <= C; i++)
        for (int j = 0; j < t; j++)
            // If the current color combination can be covered by adding one item, update the dp value
            dp[(1 << i - 1) ^ j] = min(dp[(1 << i - 1) ^ j], dp[j] + 1);

    // Output the minimum number of colors required for each item to cover all colors
    for (int i = 1; i <= N; i++)
        // Calculate the XOR value of the item's color encoding and all color combinations, and then obtain the corresponding minimum number of covering items from the dp array
        cout << C - dp[t - 1 ^ o[i]] << endl;

    return 0;
}